import pandas as pd
from util import re_util


class Product:
    def __init__(self, price, url, url_img, site, title) -> None:
        self.price = price
        self.url = url
        self.url_img = url_img
        self.title = title
        self.site = site
        self.col_name_价格 = f"{self.site}-价格"
        self.col_name_详情页链接 = f"{self.site}-详情页链接"
        self.col_name_图片链接 = f"{self.site}-图片链接"
        self.col_name_标题 = f"{self.site}-标题"

    def get_set(self) -> set:
        s = {
            f"{self.site}-价格": self.price,
            f"{self.site}-详情页链接": self.url,
            f"{self.site}-图片链接": self.url_img,
            f"{self.site}-标题": self.title,
        }
        return s

    def get_series(self) -> pd.Series:
        ser = pd.Series(self.get_set())
        ser[self.col_name_价格] = float(ser[self.col_name_价格])
        return ser


class Product_1688(Product):
    pass


class Product_Amazon(Product):
    def __init__(
        self, price, url, url_img, title, site, score, number_comments
    ) -> None:
        super().__init__(price=price, url=url, url_img=url_img, site=site, title=title)
        self.score = score
        self.number_comments = number_comments
        self.set_price(price=price)
        # self.site = site
        # print(f"pro43   {self.site}")
        # print(f"pro44   {self.price,self.url,self.url_img}")

    def set_price(self, price):
        price = str(price)
        price.replace(",", ".")
        price = re_util.get_list_tqsz_提取数字(price)[0]
        price = float(price)
        self.price = price

    def get_set(self) -> set:
        s = {
            f"{self.site}-价格": self.price,
            f"{self.site}-详情页链接": self.url,
            f"{self.site}-图片链接": self.url_img,
            f"{self.site}-标题": self.title,
            f"{self.site}-评分": self.score,
            f"{self.site}-评论数量": self.number_comments,
        }
        return s

    def test(self):
        print(self.site)
